// Copyright (c) 2002 Torvald Riegel. All rights reserved.
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

package cpne;


import javax.swing.text.*;


public class PerlExprDocument extends PlainDocument 
{
    public PerlExprDocument()
        {
            super();
        }
    public PerlExprDocument(String str)
        {
            super();
            setExpr(str);
        }
    public void setExpr(String str)
        {
            try
            {
                //TODO delete contents first !
                insertString(0, str, new SimpleAttributeSet());
            }
            catch (BadLocationException e)
            {
                // FIXME that's probably not a good way to "handle" it
                System.out.println("something went wrong: "+e.getMessage());
                System.exit(1);
            }
        }   
    public String getExpr()
        {
            try
            {
                return getText(0, getLength());
            }
            catch (javax.swing.text.BadLocationException e)
            {
                System.out.println("TODO really ignore ?"+e.getMessage());
                System.exit(1);
                return "something went wrong ...";
            }
        }
}
